#include "Table.h"

Table::Table(int size){
    TableSize = size;
    CurrentPoint = 0;
    lock = new Lock("Table lock");
    base = new void*[size];
    for(int i = 0; i < size; i++)
        base[i] = NULL;
}
Table::~Table(){
    delete lock;
    delete base;
}
int Table::Alloc(void *object){
    if(CurrentPoint == TableSize - 1)
        return -1;
    lock->Acquire();
    base[CurrentPoint] = object;
    CurrentPoint++;
    lock->Release();
    return CurrentPoint - 1;
}
void *Table::Get(int index){
    if(index>=TableSize)
        return NULL;
    void *point;
    lock->Acquire();
    point = base[index];
    lock->Release();
    return point;
}
void Table::Release(int index){
    if(index>=TableSize)
        return;
    lock->Acquire();
    for(;index<=CurrentPoint;index++){
        base[index]=base[index+1];
    }
    CurrentPoint--;
    lock->Release();
}